package utils;

import java.util.ArrayList;
import java.util.HashMap;

import dbutil.ConnectDB;

public class Validate {

	/**************************************
	 * Method name		: validateDelete
	 * Return type		: boolean
	 * Decription		:Kiem tra xem nguoi nay co duoc quyen xoa hay khong?
	 * Created date		: Jul 5, 2008
	 * Author			: Honglk
	 **************************************/
	public static boolean validateDelete(String soHC_Madoan) {
		boolean result = false;
		String userName = UtilsOnScopes.getUserName();
		String SQL="SELECT COUNT(*) as count FROM phanquyenxoasua A" +
				"  WHERE A.daduyet=1 AND A.khoa=0 AND A.xoa=1 " +
				" AND A.sohc_idgroup ='"+soHC_Madoan+"' " +
				" AND A.username='"+userName+"'";
		System.out.println(SQL);
		ArrayList<HashMap<String, Object>> array = ConnectDB
		.getDataTypeList(SQL);
		try {
			if (array.size() > 0) {
				HashMap<String, Object> hash = new HashMap<String, Object>();
				hash = (HashMap<String, Object>) array.get(0);
				String countStr = hash.get("count").toString();
				int count = Integer.parseInt(countStr);
				if(count > 0){
					return result = true;
				}
				else 
					return result = false;
			}else{
				result = false;
			}
		} catch (Exception e) {
			result = false;
			e.printStackTrace();
		}
		return result;
	}
	
	/**************************************
	 * Method name		: validateEdit
	 * Return type		: boolean
	 * Decription		:Kiem tra xem nguoi nay co duoc quyen sua hay khong?
	 * Created date		: Jul 5, 2008
	 * Author			: Honglk
	 **************************************/
	public static boolean validateEdit(String soHC_Madoan) {
		boolean result = false;
		String userName = UtilsOnScopes.getUserName();
		String SQL="SELECT COUNT(*) as count FROM phanquyenxoasua A" +
				"  WHERE A.daduyet=1 AND A.khoa=0 AND A.sua=1 " +
				" AND A.sohc_idgroup ='"+soHC_Madoan+"' " +
				" AND A.username='"+userName+"'";
		System.out.println(SQL);
		ArrayList<HashMap<String, Object>> array = ConnectDB
		.getDataTypeList(SQL);
		try {
			if (array.size() > 0) {
				HashMap<String, Object> hash = new HashMap<String, Object>();
				hash = (HashMap<String, Object>) array.get(0);
				String countStr = hash.get("count").toString();
				int count = Integer.parseInt(countStr);
				if(count > 0){
					return result = true;
				}
				else 
					return result = false;
			}else{
				result = false;
			}
		} catch (Exception e) {
			result = false;
			e.printStackTrace();
		}
		return result;
	}
	
public static void main(String[] args) {
	System.out.println(Validate.validateDelete("HC00002"));
}
}
